<template>
  <form @submit="onSubmit">
    <cell-group inset>
      <field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <field name="uploader" label="文件上传">
        <template #input>
          <uploader :after-read="afterRead" />
        </template>
      </field>
    </cell-group>
    <div style="margin: 16px">
      <Button round block type="primary" native-type="submit"> 提交 </Button>
    </div>
  </form>
</template>

<script>
import { ref } from "vue";
import { Form, Field, CellGroup, Button,Uploader } from "vant";
export default {
  name: "tousu",
  components: {
    Form,
    Field,
    CellGroup,
    Button,
    Uploader
  },
  setup() {
    const username = ref("");
    const password = ref("");
    const onSubmit = (values) => {
      console.log("submit", values);
    };

    const afterRead = (file) => {
      // 此时可以自行将文件上传至服务器
      console.log(file);
    };

    return {
      username,
      password,
      onSubmit,
      afterRead
    };
  },
};
</script>

<style lang="less" scoped>
</style>